#include "StdAfx.h"
#include "Triangle.h"

Triangle::Triangle(Vertex a, Vertex b, Vertex c)
{
	vertices[0] = a;
	vertices[1] = b;
	vertices[2] = c;
}

Triangle::~Triangle(void)
{
}


void Triangle::Draw( ESContext *esContext, Shaders* myShaders, Camera* camera)
{
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices, GL_STATIC_DRAW);
	glEnableVertexAttribArray(myShaders->positionAttribute);
	glVertexAttribPointer(myShaders->positionAttribute, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
	glEnableVertexAttribArray(myShaders->colorAtttribute);
	glVertexAttribPointer(myShaders->colorAtttribute, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (char*)0 + sizeof(Vector3));
	glEnableVertexAttribArray(myShaders->uvAttribute);
	glVertexAttribPointer(myShaders->uvAttribute, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (char*)0 + sizeof(Vector3) + sizeof(Vector4));

	glBindTexture(GL_TEXTURE_2D, textureID);
	glUniform1i(myShaders->textureUniform, 0);

	//Pass WorldMatrix
	glUniformMatrix4fv(myShaders->matViewUniform, 1, GL_FALSE, &(camera->getViewMatrix().Transpose().m[0][0]));
	glUniformMatrix4fv(myShaders->matProjectionUniform, 1, GL_FALSE, &(camera->getProjectionMatrix().Transpose().m[0][0]));
	glUniformMatrix4fv(myShaders->matWorldUniform, 1, GL_FALSE, &(worldMatrix.Transpose().m[0][0]));
	

		
	glDrawArrays(GL_TRIANGLES, 0, 3);
}

void Triangle::Update ( ESContext *esContext, float deltaTime)
{

}